//
//  CertitficationViewModel.m
//  GLGW_Shoping
//
//  Created by yang on 2018/11/22.
//  Copyright © 2018年 yang. All rights reserved.
//

#import "CertitficationViewModel.h"
#import "AliyunOSSImageUploader.h"

@implementation CertitficationViewModel{
    GLGWImageView * caridImageView;
}

-(instancetype)initWithViewToViewScrollView:(UIScrollView *)scrollView theSuperView:(UIView *)superView{
    if (self = [super initWithViewToViewScrollView:scrollView theSuperView:superView]) {
        scrollView.y = scrollView.y + kHeightProportion_In_iPhoneTriploid(10);
        scrollView.height = scrollView.height - kHeightProportion_In_iPhoneTriploid(10);
        [superView addSubview:scrollView];
        //
        GLGWLabel * topLabel = [[GLGWLabel alloc] initWithFrame:CGRectMake(0, kHeightProportion_In_iPhoneTriploid(70), KScreenWidth, kHeightProportion_In_iPhoneTriploid(22)) theFont:SYSTEMFONT(16) theColor:[UIColor colorWithHexString:@"#666666"] inSuperView:scrollView];
        topLabel.textAlignment = NSTextAlignmentCenter;
        topLabel.text = @"请上传名片以验证身份";
        //
        caridImageView = [[GLGWImageView alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(80), kY_With_View(topLabel, 40), KScreenWidth - kWidthProportion_In_iPhoneTriploid(160), kHeightProportion_In_iPhoneTriploid(135)) imageName:@"99" inSuperView:scrollView];
        caridImageView.backgroundColor = kRandomColor;
        //
        GLGWLabel * caseLabel = [[GLGWLabel alloc] initWithFrame:CGRectMake(0, kY_With_View(caridImageView, 41), KScreenWidth, kHeightProportion_In_iPhoneTriploid(20)) theFont:SYSTEMFONT(14) theColor:[UIColor colorWithHexString:@"#999999"] inSuperView:scrollView];
        caseLabel.textAlignment = NSTextAlignmentCenter;
        caseLabel.text = @"上传名片带姓名和职位的一面";
        //
        GLGWButton * comitBut = [[GLGWButton alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(15), kY_With_View(caseLabel, 60), KScreenWidth - kWidthProportion_In_iPhoneTriploid(30), kHeightProportion_In_iPhoneTriploid(44)) hTitle:@"确认提交" titleLableFont:SYSTEMFONT(16) titleLableColor:[UIColor whiteColor] theCornerRadius:kHeightProportion_In_iPhoneTriploid(22) backgroundColr:kColor_Rule_Yellow inSuperView:scrollView];
        comitBut.tag = 200;
        [comitBut addTarget:self action:@selector(comitAction:) forControlEvents:UIControlEventTouchUpInside];
        //
        GLGWButton * jumpBut = [[GLGWButton alloc] initWithFrame:CGRectMake(kWidthProportion_In_iPhoneTriploid(100), kY_With_View(comitBut, 20), KScreenWidth - kWidthProportion_In_iPhoneTriploid(200), kHeightProportion_In_iPhoneTriploid(20)) titleText:@"跳过，以后再上传" titleLableFont:SYSTEMFONT(14) titleLableColor:kColor_Rule_Yellow inSuperView:scrollView];
        jumpBut.tag = 201;
        [jumpBut addTarget:self action:@selector(comitAction:) forControlEvents:UIControlEventTouchUpInside];
        scrollView.contentSize = CGSizeMake(KScreenWidth, kY_With_View(jumpBut, 20));
    }
    return self;
}

-(void)comitAction:(GLGWButton *)sender{
    if (sender.tag == 200) {
//        UIImage * image = [UIImage imageNamed:@"upImage"];
//        [AliyunOSSImageUploader asyncUploadImage:image complete:^(NSArray<NSString *> * _Nonnull names, UploadImageState state) {
//            DLog(@"%@------%ld",names,(long)state);
//        }];
        [self requestCerData];
    }else{
        [self.delegate jumpAction];
    }
}

#pragma mark --- 数据请求。-
-(void)requestCerData{
    NSDictionary * changeDic = @{@"userId":koString(self.userId),@"businessCard":@"http://img.zcool.cn/community/01f9ea56e282836ac72531cbe0233b.jpg@2o.jpg"};
    [GLGWRequestTool POST:[NSString stringWithFormat:@"%@%@",kApiPrefix,kChangestatus] lodingView:nil lodingTextString:@"" isLoding:YES parameters:changeDic success:^(id  _Nullable response) {
        BaseModel * b_Model = [BaseModel yy_modelWithJSON:response];
        if (b_Model.code == 0) {
            if (self.delegate && [self.delegate respondsToSelector:@selector(cerComintActionOk)]) {
                [self.delegate cerComintActionOk];
            }
        }
    } failure:^(NSError * _Nullable error) {

    }];
}

@end
